package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-24
 * Time: 16:15
 */
public class Test {
    public static void main(String[] args) {
        //获得class对象的三种方式
        //第一种
        try {
            Class<?>ClassStudent = Class.forName("demo1.Student");
            Student student = (Student)ClassStudent.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        //第二种
        Class<?> c2 = Student.class;
        //第三种
        Student student = new Student();
        Class c3 = student.getClass();
    }
}
